package cn.jiahua.test14;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

public class Test3 {

    public static void main(String[] args) throws InterruptedException {

        //队列大小
        ArrayBlockingQueue blockingQueue=new ArrayBlockingQueue(3);

        //放元素
        blockingQueue.offer("a") ;
        blockingQueue.offer("b") ;
        blockingQueue.offer("c") ;
        blockingQueue.offer("d",2, TimeUnit.SECONDS) ; //等待超过2秒，就自动退出

        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll(2,TimeUnit.SECONDS));
    }
}
